<?php
namespace app\modules\home\actions;

// use Yii;
use app\lib\ActionBase;
use app\service\data as data;
use app\lib\Code;

class User extends ActionBase {
    
    private $_userdata;

    //医院名字
    public $hospitalname;
    
    //电话号码
    public $phone;
    
    //email
    public $email;
    
    //手机验证码
    public $verify;
    
    
    public function __construct() {
        $this->_userdata = new data\User();
    }
    
    public function rules() {
        return [
            //注册验证
            ['hospitalname','required','on'=>'register', 'message'=>'医院名不能为空'],
            ['phone','required','on'=>'register', 'message'=>'手机号不能为空'],
            ['email','required','on'=>'register', 'message'=>'email不能为空'],
            ['verify','required','on'=>'register', 'message'=>'验证码不能为空'],
            
            //登录验证
            ['phone','required','on'=>'register', 'message'=>'手机号不能为空'],
            ['verify','required','on'=>'login', 'message'=>'验证码不能为空'],
        ];
    }
    
    //注册
    public function Register($arrInput) {
        $this->setScenario("register");
        $this->load($arrInput, '');
        if (!$this->validate()) {
            formatJson(Code::PARAM, $this->parseErrors2str($this->firstErrors));
        }
        return $this->_userdata->Register($arrInput);
    }
    
    //登录
     public function Login($arrInput) {
        $this->setScenario("login");
        $this->load($arrInput, '');
        if (!$this->validate()) {
            formatJson(Code::PARAM, $this->parseErrors2str($this->firstErrors));
        }
        return $this->_userdata->Login($arrInput);
    }
}
